layui.extend({
    admin: '{/}../../static/js/admin'
});
var tabledata =[{
    "classroom_id": "7-4-211",
    "classroom_address": "7教4楼211教室",
    "user_id": "16000000",
    "classroomused_time": "2018-11-01 8:00-12:00",
    "user_reason": "召开班会"
}, {
    "classroom_id": "12-1-106",
    "classroom_address": "12教1楼106教室",
    "user_id": "14050003",
    "classroomused_time": "2018-11-05 18:00-21:00",
    "user_reason": "组织活动"
}];
window.onload=firstsearch();
//drawtable(tabledata);
function drawtable(data) {
    layui.use(['table', 'jquery', 'form', 'admin'], function () {
        var table = layui.table,
            $ = layui.jquery,
            form = layui.form,
            admin = layui.admin;

        table.render({
            elem: '#articleList',
            cellMinWidth: 80,
            cols: [
                [{
                    field: 'apply_classroom_id', title: '教室ID', sort: true
                }, {
                    field: 'apply_status', title: '处理状态'
                }, {
                    field: 'user_id', title: '使用人员ID'
                }, {
                    field: 'user_date', title: '使用时间'
                }, {
                    field: 'purpose', title: '使用原由'
                }]
            ],
            data: data,
            event: true,
            page: true
        });
        /*
         *数据表格中form表单元素是动态插入,所以需要更新渲染下
         * http://www.layui.com/doc/modules/form.html#render
         * */
        $(function () {
            form.render();
        });

        var active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('articleList'),
                    data = checkStatus.data;
                //console.log(data);
                //layer.alert(JSON.stringify(data));
                if (data.length > 0) {
                    layer.confirm('确认要删除吗？' + JSON.stringify(data), function (index) {
                        layer.msg('删除成功', {
                            icon: 1
                        });
                        //找到所有被选中的，发异步进行删除
                        $(".layui-table-body .layui-form-checked").parents('tr').remove();
                    });
                } else {
                    layer.msg("请先选择需要删除的文章！");
                }

            },
            Recommend: function () {
                var checkStatus = table.checkStatus('articleList'),
                    data = checkStatus.data;
                if (data.length > 0) {
                    layer.msg("您点击了推荐操作");
                    for (var i = 0; i < data.length; i++) {
                        console.log("a:" + data[i].recommend);
                        data[i].recommend = "checked";
                        console.log("aa:" + data[i].recommend);
                        form.render();
                    }

                } else {
                    console.log("b");
                    layer.msg("请先选择");
                }

                //$(".layui-table-body .layui-form-checked").parents('tr').children().children('input[name="zzz"]').attr("checked","checked");
            },
            Top: function () {
                layer.msg("您点击了置顶操作");
            },
            Review: function () {
                layer.msg("您点击了审核操作");
            }

        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        /*用户-删除*/
        window.member_del = function (obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                //发异步删除数据
                $(obj).parents("tr").remove();
                layer.msg('已删除!', {
                    icon: 1,
                    time: 1000
                });
            });
        }

    });
}
function delAll(argument) {
    var data = tableCheck.getData();
    layer.confirm('确认要删除吗？' + data, function(index) {
        //捉到所有被选中的，发异步进行删除
        layer.msg('删除成功', {
            icon: 1
        });
        $(".layui-form-checked").not('.header').parents('tr').remove();
    });
}

function search(){
    console.log("search()");
    var classroomused_Time = document.getElementById("classroomused_time").value;
    var classroom_Id = document.getElementById("classroom_Id").value;
    var user_Id = document.getElementById("classroom_userId").value;
    var transform = {"classroomused_time":classroomused_Time,"classroom_Id":classroom_Id,"user_Id":user_Id}
    console.log(transform)
    $.ajax({
        dataType:"json",
        type:"post",
        url:"/history_advanced_passed.action",
        data:transform,
        success:function(data){
            tabledata = data.tabledata;
            console.log(tabledata);
        },
        error:function() {
            //window.alert("查询有误！");
            console.log("查询有误");
        },
        complete:function(){
            drawtable(tabledata);
        }
    })
}

function firstsearch(){
    $.ajax({
        dataType:"json",
        type:"post",
        url:"/history_advanced_passed.action",
        data:{},
        success:function(data){
            tabledata = data.tabledata;
            console.log(tabledata)
        },
        error:function(){
            //window.alert("页面初始化加载有误！");
            console.log("页面加载有误！");
        },
        complete:function(){
            drawtable(tabledata)
        }
    })
}